package com.sgb.merchant.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.sgb.link.entity.merchant.DemandListEntity;
import com.sgb.link.entity.merchant.SelfProjectList;
import com.sgb.merchant.api.MerchantsNet;
import com.sgb.net.entity.ListResponse;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.util.MToast;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author: 王彬臣
 * @date: 2021/9/16
 * @Description: 我的投资需求列表ViewModel
 */
public class SelfDemandListModel extends BaseViewModel {
    public MutableLiveData<ListResponse<List<DemandListEntity>>> liveDataInvestment = new MutableLiveData<>();

    public MutableLiveData<Boolean> ldDel=new MutableLiveData<>();
    public MutableLiveData<Boolean> ldState=new MutableLiveData<>();
    private int pageNum = 1;
    public SelfDemandListModel(@NonNull @NotNull Application application) {
        super(application);
    }
    public void getInvestmentData(boolean isLoadMore, Map<String, Object> map) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        map.put("page", pageNum);
        map.put("limit", 20);
        MerchantsNet.getInstance().getService().getSelfDemandList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<DemandListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<DemandListEntity>>> data) {
                if(data.isSuccess()){
                    liveDataInvestment.postValue(data.getData());
                }
            }
        });
    }
    public void delProject(String no){
        MerchantsNet.getInstance().getService().delDemand(no).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                if(data.isSuccess()){
                    MToast.showToast(getApplication(),"删除成功");
                    ldDel.postValue(true);
                }
            }
        });
    }
    public void updateDemands(String no,String status){
        MerchantsNet.getInstance().getService().updateDemands(no,status).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                if(data.isSuccess()){
                    ldState.postValue(true);
                }
            }
        });
    }
}
